<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive" />
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive" />
  </div>
</template>

<script>
  export default {
    mounted() {
      this.event()
    },
    methods: {
      // 沉浸式体验 防退出
      event() {
        document.addEventListener('plusready', function () {
          var webview = plus.webview.currentWebview()
          // 沉浸式体验
          plus.navigator.setStatusBarStyle('light')
          plus.navigator.setStatusBarBackground('#000000')
          // 防退出
          plus.key.addEventListener('backbutton', function () {
            webview.canBack(function (e) {
              if (e.canBack) {
                sessionStorage.setItem('isBack',true)
                webview.back()
              } else {
                var first = null
                plus.key.addEventListener(
                  'backbutton',
                  function () {
                    if (!first) {
                      first = new Date().getTime()
                      setTimeout(function () {
                        first = null
                      }, 1000)
                    } else {
                      if (new Date().getTime() - first < 1500) {
                        plus.runtime.quit()
                      }
                    }
                  },
                  false
                )
              }
            })
          })
        })
      },
    },
  }
</script>
